module.exports = function (sequelize, Sequelize) {
	// 地址模型：验证会自动在 create, update 和 save 时运行
	return sequelize.define("AddressModel", {
		id: { 
			type: Sequelize.INTEGER, 
			primaryKey: true,
			autoIncrement: true,
			allowNull: false
		},
		user_id: {
			type: Sequelize.INTEGER,
			allowNull:false,
			validate: {
				isInt: true,
				notNull: true
			},
		},
		receive_name: {
			type: Sequelize.STRING(50),
			allowNull: false,
			validate: {
				notEmpty: true,
				notNull: true
			},
		},
		receive_tel: {
			type: Sequelize.STRING(11),
			allowNull: false,
			validate: {
				notEmpty: true,
				notNull: true
			},
		},
		receive_address_full: {
			type: Sequelize.STRING(255),
			allowNull: false,
			validate: {
				notEmpty: true,
				notNull: true
			},
		},
		receive_address_detail: {
			type: Sequelize.STRING(255),
			allowNull: false,
			validate: {
				notEmpty: true,
				notNull: true
			},
		},
		area_code: {
			type: Sequelize.STRING(6),
			allowNull: false,
			validate: {
				notEmpty: true,
				notNull: true
			},
		},
		is_default: {
			type:Sequelize.INTEGER,
			validate: {
				isIn: [[0, 1]],
			},
			set(value) {
				var delNum = 0;
				if(value && String(value)=="true") delNum = 1;
				this.setDataValue('is_default', delNum);
			}
		}
	}, {
		tableName: "address"
	});
}